<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/jh/admin/components/meta.html" />
    <title>渠道管理 ${metaTitleSuffix!}</title>
    <#include "/jh/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="4-1" />
            <#include "/jh/admin/components/menu.html" />
            <el-container>
                <#include "/jh/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12">
                                <div class="title theme-color1">渠道管理</div>
                            </el-col>
                            <el-col :span="12">
                                <div class="operations">
                                    <el-button type="success" size="small" @click="add"><i class="el-icon-plus"></i>添加</el-button>
                                </div>
                            </el-col>
                        </el-row>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%">
                            <el-table-column prop="columns.name" label="渠道名称" show-overflow-tooltip>
                                <template slot-scope="scope">
                                    <el-button @click="child(scope.row.columns)" type="text" size="small">{{ scope.row.columns.name }}</el-button>
                                </template>
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="100">
                                <template slot-scope="scope">
                                    <el-button @click="edit(scope.row.columns)" type="text" size="small">编辑</el-button>
                                    <el-button @click="del(scope.row.columns)" type="text" size="small" style="color: red;">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <#include "/jh/admin/components/page.html" />
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <el-dialog title="渠道信息" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="渠道名称" label-width="90px">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </div>
        </el-dialog>
        <#include "/jh/admin/components/footer.html" />
    </div>
    <#include "/jh/admin/components/scripts.html" />
    <script>
        var vue = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                dialogFormVisible: false,
                form: {
                    id: '',
                    name: '',
                    channelId: '${channelId!}'
                }
            }
        },
        mounted: function() {
            // var str = '${items!}'
            // if (str != '') {
            //     this.list = JSON.parse(str);
            // }
        },
        methods: {
            add() {
                this.form = {
                    id: '',
                    name: '',
                    channelId: '${channelId!}'
                };
                this.dialogFormVisible = true;
            },
            edit(item) {
                var self = this;
                var param = Qs.stringify({
                    channelId: item.id
                });
                loading();
                axios({
                    url: '/jh/admin/channel/info',
                    method: 'post',
                    data: param,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).then(function(response) {
                    if (response.data.status == 200) {
                        var info = response.data.info;
                        self.form = {
                            id: info.id,
                            name: info.name,
                            channelId: info.channelId
                        }
                        self.dialogFormVisible = true;
                        endLoading();
                    } else {
                        endLoading();
                        msg(response.data.msg);
                        console.log(response.data);
                    }
                }).catch(function(error) {
                    endLoading();
                    msg("保存失败");
                    console.log(error);
                });
            },
            child(item) {
                window.location.href = "/jh/admin/channel/list?channelId=" + item.id;
            },
            del(item) {
                var self = this;
                confirm("确认删除？请谨慎操作", "确认", function() {
                    loading();
                    var param = Qs.stringify({
                        channelId: item.id
                    });
                    axios({
                        url: '/jh/admin/channel/delete',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {
                        if (response.data.status == 200) {
                            endLoading();
                            window.location.href = "/jh/admin/channel/list?channelId=${channelId!}";
                            // msg("登录成功");
                        } else {
                            endLoading();
                            msg(response.data.msg);
                            console.log(response.data);
                        }
                    })
                    .catch(function(error) {
                        endLoading();
                        msg("删除失败");
                        console.log(error);
                    });
                })
            },
            submit() {
                var self = this;
                var param = Qs.stringify({
                    id: self.form.id,
                    name: self.form.name,
                    channelId: self.form.channelId
                });
                loading();
                axios({
                    url: '/jh/admin/channel/submit',
                    method: 'post',
                    data: param,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).then(function(response) {
                    if (response.data.status == 200) {
                        endLoading();
                        window.location.href = "/jh/admin/channel/list?channelId=${channelId!}";
                        // msg("登录成功");
                    } else {
                        endLoading();
                        msg(response.data.msg);
                        console.log(response.data);
                    }
                }).catch(function(error) {
                    endLoading();
                    msg("保存失败");
                    console.log(error);
                });
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <script>
        vue.list = ${items!}
    </script>
    <#include "/jh/admin/components/msg.html" />
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }
    </style>
</body>

</html>